package com.itheima.pojo;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.core.toolkit.AES;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Dept {
    @TableId(value = "id",type = IdType.AUTO)
    private Integer id;
    private String name;
    //fill填充，什么时候，INSERT，执行insert语句(自动填充)
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;
    //fill填充，什么时候，INSERT_UPDATE，执行insert和update语句
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;

    public static void main(String[] args) {
        //IdWork是MybatisPlus 提供的，默认生成主键的方式，它是一个long类型，雪花算法
        // 全局唯一
        //System.out.println(IdWorker.getId());
        // 生成16位随机AES密钥
        String randomKey = AES.generateRandomKey();
        System.out.println("--mpw.key=" + randomKey);
        String jdbcUrl = "jdbc:mysql://localhost:3306/tlias?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true";
        String root = "root";
        String password = "1234";
        // 使用随机密钥加密数据
        System.out.println(AES.encrypt(jdbcUrl, randomKey));
        System.out.println(AES.encrypt(root, randomKey));
        System.out.println(AES.encrypt(password, randomKey));
    }
}